package soft.quicknote.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import soft.quicknote.DBHelper;
import soft.quicknote.beans.Category;

public class CategoryNameAdapter extends ArrayAdapter<Category> {

    // View lookup cache
    private static class ViewHolder {
        TextView text;
    }


    ArrayList<Category> mCats;
    DBHelper helper;

    public CategoryNameAdapter(Context context, ArrayList<Category> cats) {
        super(context, 0, cats);
        mCats = cats;
        helper = new DBHelper(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Category cat = getItem(position);

        CategoryNameAdapter.ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new CategoryNameAdapter.ViewHolder();
            LayoutInflater inflater = LayoutInflater.from(getContext());
            convertView = inflater.inflate(android.R.layout.simple_spinner_item, parent, false);
            viewHolder.text = (TextView) convertView.findViewById(android.R.id.text1);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (CategoryNameAdapter.ViewHolder) convertView.getTag();
        }
        viewHolder.text.setText(cat.getName());
        return convertView;
    }
}
